<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr = [1, 2, 3, 4, 5];

      function slice(arr, start, end) {
        const newarr = [];
        for (let i = 0; i < arr.length; i++) {
          if (i >= start && i < end) {
            newarr.push(arr[i]); // 复制数组
          }
        }
        return newarr;
      }
      console.log(slice(arr, 1, 4));
    </script>
  </body>
</html>
